package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.security.Security;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.SetMealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mobile/setmeal")
@Slf4j
public class MobileSetMealController {

    @Autowired
    private SetMealService setMealService;
    @Autowired
    private CheckGroupService checkGroupService;
    @Autowired
    private CheckItemService checkItemService;


    /**
     * 查询套餐
     * @return
     */
    @GetMapping("/getSetmeal")
    public Result getSetmeal() {
        List<Setmeal> setmealList = setMealService.findAll();
        return new Result(true, MessageConst.ACTION_SUCCESS, setmealList);
    }


    @GetMapping("/findById")
    public Result findById(Integer id) {
        //检查组信息
        List<CheckGroup> checkGroupList = checkGroupService.findBySetmalId(id);
        //检查项信息
        for (CheckGroup checkGroup : checkGroupList) {
            List<CheckItem> checkItemList = checkItemService.findByCheckgroupId(checkGroup.getId());
            checkGroup.setCheckItems(checkItemList);
        }
        //套餐信息
        Setmeal setmeal = setMealService.getone(id);
        setmeal.setCheckGroups(checkGroupList);

        return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS, setmeal);

    }
}